package net.ecpt.dubbo;

import java.util.Map;

import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.ServiceUtil;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Consumer {
    public static void main(String[] args) throws Exception {
	// ClassPathXmlApplicationContext context = new
	// ClassPathXmlApplicationContext("echo-consumer.xml");
	String consumer = "ofdubbo/echo-consumer.xml";
	ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(consumer);

	context.start();
	// 获取远程服务代理
	DemoService demoService = (DemoService) context.getBean("demoService");
	// 执行远程方法
	String hello = demoService.sayHello("world");
	// Hello world
	System.out.println(hello);
    }

    public static Map<String, Object> springConsumer(DispatchContext ctx, Map<String, ? extends Object> context) {
	Map<String, Object> result = ServiceUtil.returnSuccess();
//	Delegator delegator = ctx.getDelegator();
	String consumer = "ofdubbo/echo-consumer.xml";
	ClassPathXmlApplicationContext context1 = new ClassPathXmlApplicationContext(consumer);
	context1.start();
	// 获取远程服务代理
	DemoService demoService = (DemoService) context1.getBean("demoService");
	// 执行远程方法
	String hello = demoService.sayHello("world");
	// Hello world
	System.out.println(hello);
	
	context1.close();
	return result;
    }

}
